package com.ai.aicodeinghelper.controller;

import com.alibaba.cloud.ai.dashscope.image.DashScopeImageModel;
import com.alibaba.cloud.ai.dashscope.image.DashScopeImageOptions;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.image.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class ImageController {

    private final ImageModel imageModel;

    private static final String DEFAULT_PROMPT = "为人工智能生成一张富有科技感的图片！";

    public ImageController(DashScopeImageModel imageModel) {
        this.imageModel = imageModel;
    }

    @GetMapping("/image")
    public void image(String input) {
        DashScopeImageOptions options = DashScopeImageOptions.builder()
                .withHeight(512)
                .withWidth(512)
                .withModel("wanx2.1-t2i-turbo")
                .build();


        ImagePrompt imagePrompt = new ImagePrompt(input, options);

        ImageResponse response = imageModel.call(imagePrompt);
        String imageUrl = response.getResult().getOutput().getUrl();
        log.info("imageUrl: {}", imageUrl);
        log.info("imagePrompt: {}", imagePrompt);
    }

}
